using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Xml;
using System.Web.UI;

public partial class P : Page
{
    protected void Page_Init(object sender,EventArgs e)
    {
        //this.Title = this.Title+"xxxxyyyykkk";
    }
    protected void Page_Load( object sender,EventArgs e )
    {
    }

    // Handler
    public static string Handler( NameValueCollection nvc )
    {
        string code = nvc["code"];
        if( string.IsNullOrEmpty(code) ){
            return "";
        }

        // 生成代码
        return InterfaceTo.GenMethods( code );
    }
}

//任务
// 1.清除注释,两种//与/**/
// 2.根据分号分割成独立的一个个接口,并加上public,生成函数体,全部都是抛出"未实现"的错误
public class InterfaceTo
{

    private static string methodText = 
@"        public {0}
        {{
            throw new Exception( ""未实现或不支持"" );
        }}";

    public static string GenMethods( string interfaceText )
    {
        interfaceText = interfaceText.Trim();
        interfaceText = interfaceText.TrimEnd(';');
        //1
        string reg = "//.*$";
        interfaceText = Regex.Replace( interfaceText,reg,"",RegexOptions.Multiline );
        reg = @"/\*.*?\*/";
        interfaceText = Regex.Replace( interfaceText,reg,"",RegexOptions.Singleline );
        
        //2
        string[] ss = Regex.Split( interfaceText,";" );
        for( int i=0,len=ss.Length;i<len;i++ )
            ss[i] = string.Format( methodText,ss[i].Trim() );
            
        return string.Join( "\r\n\r\n",ss );
    }
}
